import {defineConfig,loadEnv} from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";
import  sysConfig from './src/config'
// https://vitejs.dev/config/


export default defineConfig(({ command, mode }) => {
    // 根据当前工作目录中的 `mode` 加载 .env 文件
    // 设置第三个参数为 '' 来加载所有环境变量，而不管是否有 `VITE_` 前缀。
    const env = loadEnv(mode, process.cwd(), '')
    return {
        // vite 配置
        base:'./',
        plugins: [
            vue(),
            AutoImport({
                imports: ['vue','vue-router'],
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            })
        ],
        server:{
            host: '0.0.0.0',
            proxy: {
                '/api/': {
                    ws: true,
                    target:env.VITE_API_BASE_URL,
                    changeOrigin: true,
                    rewrite: (p) => p.replace(/^\/api/, ''),
                },
            },
        },
        css: {
            preprocessorOptions: {
                scss: {
                    api: "modern-compiler",
                    additionalData:'@import "@/styles/variable.scss";'
                },
            }
        },
        resolve: {
            extensions: ['.js', '.ts', '.json', '.tsx'],
            alias: {
                '@': '/src', // 将 '@' 别名映射到项目的 'src' 目录
            }
        }
    }
})
